<template>
    <!-- 总容器 -->
    <div class="wrapper">
        <h1>牢大体检预约中心</h1>
        <section>
            <div class="input-box">
                <i class="fa fa-user-o"></i>
                <input type="text" v-model="form.userId" placeholder="输入手机号">
            </div>
            <div class="input-box">
                <i class="fa fa-lock"></i>
                <input type="password" v-model="form.password" placeholder="输入登录密码">
            </div>
            <div class="reg-box">
                <p onclick="location.href='register'">注册</p>
                <p @click="toupdatePassword()">忘记密码？</p>
            </div>
            <div class="button-box" @click="handleLogin(form)">登录</div>
            
            <!-- 移动过来的页脚内容 -->
            <div class="footer-content">
                <div class="line"></div>
                <p>有疑问请联系客服</p>
                <div class="line"></div>
            </div>
            <p class="footer-phone">1234-567-890</p>
        </section>
    </div>
</template>

<script setup>
import { ElMessage } from 'element-plus';
const router = useRouter();

import{login} from '@/api/user'
import { setToken } from '@/utils/auth'
const data = reactive({
    form: {
    userId:'',
    password:''
    }
});

const {  form } = toRefs(data);
function handleLogin(form){
    if (!form.userId) {
        ElMessage.error('账号不能为空');
        return;
    }
    if (!form.password) {
        ElMessage.error('密码不能为空');
        return;
    }
    if (form.userId.length < 11) {
        ElMessage.error('手机号长度必须不低于11位');
        return;
    }
    login(form).then((response) => {
        if (response.data.code == 1) {
            setToken(response.data.data.token);
            ElMessage.success('登录成功');
            router.push('/index');// 示例跳转到仪表盘页面
        } else {
            ElMessage.alert(response.data.msg);
            this.loading = false
        }
    });
}

function toupdatePassword(){
    router.push("/updateVerify")
}
</script>

<style scoped>
/*********************** 总容器 ***********************/
.wrapper {
    width: 100%;
    height: 100vh; /* 使用视口高度确保全屏 */
    background: linear-gradient(45deg, #FFFFFF, #266C9F);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

/*********************** 标题部分 ***********************/
h1 {
    text-align: center;
    font-size: 9.5vw;
    font-weight: 500;
    margin-bottom: 3vh;
    background: linear-gradient(-45deg, #FFD700, #FF8C00); /* 使用与背景相反的渐变方向和颜色 */
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent; /* 设置文字颜色为透明，以便背景渐变显示 */
}

/*********************** 内容部分 ***********************/
section {
    width: 86vw;
    background-color: #FFF;
    border-radius: 2.4vw;
    box-sizing: border-box;
    padding: 6vw;
    text-align: center;
}

/*********************** 输入框样式 ***********************/
.input-box {
    width: 100%;
    height: 12vw;
    border: solid 1px #CCC;
    border-radius: 2vw;
    margin-top: 5vw;
    display: flex;
    align-items: center;
}

.input-box i {
    margin: 0 3.6vw;
    font-size: 5.4vw;
    color: #CCC;
}

.input-box input {
    border: none;
    outline: none;
    flex: 1;
}

/*********************** 注册和忘记密码样式 ***********************/
.reg-box {
    width: 100%;
    display: flex;
    justify-content: space-between;
    margin-top: 5vw;
    margin-bottom: 2vw;
}

.reg-box p {
    font-size: 3.3vw;
    color: #2D727E;
    user-select: none;
    cursor: pointer;
}

/*********************** 登录按钮样式 ***********************/
.button-box {
    width: 100%;
    height: 13vw;
    border-radius: 2vw;
    background-color: #70B0BC;
    text-align: center;
    line-height: 13vw;
    font-size: 4.6vw;
    color: #FFF;
    letter-spacing: 1vw;
    user-select: none;
    cursor: pointer;
    margin-top: 5vw;
}

/*********************** 移动过来的页脚内容样式 ***********************/
.footer-content {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 5.5vw;
}

.footer-content .line {
    width: 15vw;
    height: 1px;
    background-color: #CCC;
}

.footer-phone {
    text-align: center;
    margin-top: 2vw;
    font-size: 3.8vw;
    color: #000000;
}
</style>